<!doctype html>
<html lang="zh-CN">
<head>
  <base href="/">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="Epilog Theme">
  <title>管理员登录界面</title>

  <!-- Favicons -->
  <link rel="icon" type="image/png" href="assets/images/favicon.png">

  <!-- CSS Files -->
  <link rel="stylesheet" href="assets/css/aos.css">
  <link rel="stylesheet" href="assets/css/animate.min.css">
  <link rel="stylesheet" href="assets/css/boxicons.min.css">
  <link rel="stylesheet" href="assets/css/owl.carousel.min.css">
  <link rel="stylesheet" href="assets/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/css/mailform.css">
  <link rel="stylesheet" href="assets/css/style.css?v=1.0.1">
  <link rel="stylesheet" href="assets/css/responsive.css?v=1.0.1">
  <link rel="stylesheet" href="layui/css/layui.css">
</head>
<body>
<!-- Signin Area Start -->
<div class="bl-account-wrapper">
  <div class="container">
    <div class="row">
      <div class="col-md-6 offset-md-3">
        <div class="signup-wrapper">
          <form action="#" method="post">
            <h4>管理员登录</h4>
            <div class="form-group">
              <label for="adminname">用户名 <span class="required">*</span></label>
              <input type="text" required class="form-control" id="adminname" name="adminname">
            </div>
            <div class="form-group">
              <label for="password">密码 <span class="required">*</span></label>
              <input type="password" required class="form-control" id="password" name="password">
            </div>

            <div class="form-check mt-2 mb-2">
              <input class="form-check-input" type="checkbox" value="" id="rememberMe">
              <label class="form-check-label" for="rememberMe">
                记住我
              </label>
            </div>
            <button type="button" class="btn btn-primary login-btn">登录</button>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- Signin Area End -->

<!-- JS Script -->
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/popper.min.js"></script>
<script src="./assets/js/aos.js"></script>
<script src="./assets/js/mailform.js"></script>
<script src="./assets/js/owl.carousel.min.js"></script>
<script src="./assets/js/main.js?v=1.0.0"></script>
<script src="layui/layui.all.js"></script>

<script>
  const $ = layui.$;
  const layer = layui.layer;
  $(".login-btn").click(function () {
    let adminname = $("[name='adminname']").val();
    let password = $("[name='password']").val();

    let reg = /^[a-zA-Z0-9]{6,16}$/;
    if (reg.test(adminname) && reg.test(password)) {
      // 登录
      $.ajax({
        url: 'system/doadminlogin',
        type: 'POST',
        data: { adminname: adminname, password: password },
        success: function (result) {
          console.log(result);
          if (result === "success") {
            layer.msg("登录成功", { icon: 1 });
            setTimeout(function () {
              window.location.href = "/system/admin";
            }, 1800);
          } else {
            layer.msg("登录失败");
          }
        }
      });
    } else {
      layer.msg("用户名和密码必须是6-16位字符数字");
    }
  });
</script>
</body>
</html>